package bma.common.thrift.xdom.impl;

import java.util.ArrayList;
import java.util.List;

import bma.common.thrift.xdom.DynamicThriftManager;
import bma.common.thrift.xdom.TDynamicFunction;
import bma.common.thrift.xdom.TDynamicStruct;

public class DynamicThriftManagerHub implements DynamicThriftManager {

	private List<DynamicThriftManager> managers;

	public List<DynamicThriftManager> getManagers() {
		return managers;
	}

	public void setManagers(List<DynamicThriftManager> managers) {
		this.managers = managers;
	}

	public void addManager(DynamicThriftManager m) {
		if (this.managers == null)
			this.managers = new ArrayList<DynamicThriftManager>();
		this.managers.add(m);
	}

	@Override
	public TDynamicFunction getFunction(String name) {
		if (this.managers == null)
			return null;
		for (DynamicThriftManager m : managers) {
			TDynamicFunction f = m.getFunction(name);
			if (f != null)
				return f;
		}
		return null;
	}

	@Override
	public TDynamicStruct getStruct(String name) {
		if (this.managers == null)
			return null;
		for (DynamicThriftManager m : managers) {
			TDynamicStruct f = m.getStruct(name);
			if (f != null)
				return f;
		}
		return null;
	}

	@Override
	public int getEnumValue(String enumName, String enumString) {
		if (this.managers == null)
			return -1;
		for (DynamicThriftManager m : managers) {
			int r = m.getEnumValue(enumName, enumString);
			if (r != -1)
				return r;
		}
		return -1;
	}

}
